<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>登录注册切换动画</title>
    <style>
        /* 基础样式 */
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }

        body {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #f0f2f5;
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
        }

        /* 容器样式 */
        .auth-container {
            background: white;
            width: 400px;
            padding: 40px;
            border-radius: 12px;
            box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            position: relative;
            overflow: hidden;
        }

        /* 表单容器 */
        .forms-wrapper {
            position: relative;
            height: 480px;
            /* 根据内容高度调整 */
            transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
            /* 修改过渡时间 */
        }

        /* 表单通用样式 */
        .auth-form {
            position: absolute;
            width: 100%;
            opacity: 0;
            transform: translateX(100%);
            transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
            /* 修改过渡时间 */
            pointer-events: none;
        }

        /* 激活状态 */
        .auth-form.active {
            opacity: 1;
            transform: translateX(0);
            pointer-events: auto;
            transition-delay: 0.1s;
        }

        /* 登录表单反向动画 */
        .forms-wrapper.reverse-animation .login-form.active {
            transform: translateX(-100%);
            opacity: 0;
            /* 添加透明度过渡 */
            transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
            /* 修改过渡时间 */
        }

        /* 表单元素样式 */
        h2 {
            text-align: center;
            margin-bottom: 30px;
            color: #1a1a1a;
            font-size: 28px;
        }

        .form-group {
            margin-bottom: 20px;
        }

        input {
            width: 100%;
            padding: 14px;
            border: 2px solid #e6e6e6;
            border-radius: 8px;
            font-size: 16px;
            transition: border-color 0.3s ease;
        }

        input:focus {
            outline: none;
            border-color: #007bff;
        }

        button {
            width: 100%;
            padding: 14px;
            background: #007bff;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 16px;
            cursor: pointer;
            transition: background 0.3s ease;
        }

        button:hover {
            background: #0056b3;
        }

        /* 辅助链接 */
        .switch-link {
            text-align: center;
            margin-top: 20px;
            color: #666;
        }

        .switch-link a {
            color: #007bff;
            text-decoration: none;
            font-weight: 500;
            transition: color 0.3s ease;
        }

        .switch-link a:hover {
            color: #0056b3;
        }

        .forgot-password {
            display: block;
            text-align: right;
            margin: 10px 0 20px;
            color: #666;
            text-decoration: none;
            transition: color 0.3s ease;
        }

        .forgot-password:hover {
            color: #1a1a1a;
        }

        /* 移动端适配 */
        @media (max-width: 480px) {
            .auth-container {
                width: 90%;
                padding: 30px;
            }

            .forms-wrapper {
                height: auto;
                min-height: 400px;
            }
        }

        /* 添加 fade-out 类的 CSS 样式 */
        .forms-wrapper.fade-out {
            opacity: 0;
        }
    </style>
</head>

<body>
    <div class="auth-container">


        <!-- 登录表单 -->
        <form class="auth-form login-form">
            <h2>欢迎回来</h2>
            <div class="form-group">
                <input type="text" placeholder="用户名/邮箱" required>
            </div>
            <div class="form-group">
                <input type="password" placeholder="密码" required>
            </div>
            <a href="#" class="forgot-password">忘记密码？</a>
            <button type="submit">立即登录</button>
            <div class="switch-link">
                没有账户？ <a href="#register">立即注册</a>
            </div>
        </form>
    </div>
    </div>

    <script>
        document.addEventListener('DOMContentLoaded', function () {
            // 表单切换逻辑
            document.querySelectorAll('.switch-link a').forEach(link => {
                link.addEventListener('click', (e) => {
                    e.preventDefault();
                    const target = link.getAttribute('href');
                    const formsWrapper = document.querySelector('.forms-wrapper');

                    // 添加过渡类
                    formsWrapper.classList.add('fade-out');

                    setTimeout(() => {
                        // 切换表单
                        document.querySelectorAll('.auth-form').forEach(form => {
                            form.classList.remove('active');
                        });

                        if (target === '#login') {
                            document.querySelector('.login-form').classList.add('active');
                            formsWrapper.classList.add('reverse-animation');
                        } else if (target === '#register') {
                            document.querySelector('.register-form').classList.add('active');
                            formsWrapper.classList.remove('reverse-animation');
                        }

                        // 移除过渡类
                        formsWrapper.classList.remove('fade-out');
                    }, 500); // 修改延迟时间
                });
            });

            // 自动聚焦输入框
            document.querySelectorAll('.auth-form').forEach(form => {
                form.addEventListener('transitionend', () => {
                    if (form.classList.contains('active')) {
                        form.querySelector('input').focus();
                    }
                });
            });
        });
    </script>
</body>

</html>